package com.cssw.fyzb.busi.api.system;

import com.cssw.fyzb.busi.service.system.WordCmdService;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.Function;
import com.ydn.appserver.annotations.Parameter;
import com.ydn.appserver.annotations.Type;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * 分享直播
 *
 * @author YangYiQun
 */
@Function(description = "分享直播", parameters = {
        @Parameter(name = "userId", type = Type.Integer, description = "用户标识", required = true),
        @Parameter(name = "liveId", type = Type.String, description = "直播标识", required = true),
        @Parameter(name = "type", type = Type.String, description = "类型（1-微信 2-朋友圈）", required = true)
})
@Component
public class ShareLiveWord implements Action {

    @Autowired
    private WordCmdService wordCmdService;

    private static final Logger logger = LoggerFactory.getLogger(ShareLiveWord.class);

    @Override
    public Response execute(Request request) throws Exception {
        Long userId = request.getLong("userId");
        Long liveId = request.getLong("liveId");
        String type = request.getString("type");
        try {
            String content = wordCmdService.shareLiveWord(userId, liveId, type);
            Map<String, String> param = new HashMap<>();
            param.put("content", content);
            return Response.success().put("data", param);
        } catch (Exception e) {
            logger.info("", e);
            return Response.fail("操作异常");
        }
    }
}
